const { Service } = require('dx-router-admin');
const materialEntity = require('../entity/material.js');

module.exports = class Material extends Service {
	constructor(ctx) {
		super(ctx);
		this.entity = materialEntity;
	}
	async getList({type=0,category_id}){
		let entity = this.where('type',type);
        if(category_id){
			entity = entity.where('category_id',category_id)
		}
        return await entity.select();
	}
	category() {
		return this.hasOne('dx-exclusive-category', 'category_id', '_id').field(['name']);
	}
};